package com.e3.web.widget.model;

import com.extjs.gxt.ui.client.data.BaseModelData;

public class ListTypeModel<T> extends BaseModelData {
	private static final long serialVersionUID = 3038346401340956479L;
	
	public final static String VALUE = "value";
	public final static String NAME = "name";
	
	public ListTypeModel(T value,String name){
		setValue(value);
		setName(name);
	}
	
	public ListTypeModel(){
			
	}
	
	@SuppressWarnings("unchecked")
	public T getValue() {
		return (T)get(VALUE);
	}

	public void setValue(T value) {
		set(VALUE,value);
	}

	public String getName() {
		return get(NAME);
	}

	public void setName(String name) {
		set(NAME,name);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object obj) {
		if(obj==this){
			return true;
		}
		
		if(!(obj instanceof ListTypeModel)){
			return false;
		}
		
		ListTypeModel<T> model = (ListTypeModel<T>)obj;
		if(model!=null&&this.getValue()!=null){
			if(model.getValue()==this.getValue()||this.getValue().equals(model.getValue())){
				return true;
			}
		}
		
		return false;
	}

	public String toString(){
		return getName();
	}

}
